home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / File / Trash Desktop DB < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.0 KB  |  141 lines  |  [TEXT/ToyS]

  1. -- Preferences
  2. property kasPrefName : "Trash Desktop DB 1.0"
  3. property kasDontDo : {"Trash", "Temporary Items", "Icon" & return, "VM Storage", "OpenFolderListDF" & return, "DesktopPrinters DB"}
  4.  
  5. -- Globals
  6. global gasInfoWind -- Info window
  7. global gasInfoPos -- Position of info window
  8. global gasTrashed -- Number gone!
  9. global gasChecked -- Number checked!
  10.  
  11.  
  12. on run
  13.     -- Load prefs, show window
  14.     pfLoad()
  15.     
  16.     set gasTrashed to 0
  17.     set gasChecked to 0
  18.     set fsObjs to {}
  19.     
  20.     set gasInfoWind to display info titled kasPrefName ¬
  21.         located at gasInfoPos ¬
  22.         message "Scanning…"
  23.     
  24.     -- Get all root files/folders on writable volumes
  25.     repeat with n from 1 to 256
  26.         try
  27.             set vInfo to the volume info of volume index n
  28.         on error
  29.             exit repeat
  30.         end try
  31.         
  32.         -- Only writable volumes
  33.         if not vol read only of vInfo then
  34.             -- Get invisible items in root directory
  35.             set rootFiles to the entries in (vol alias of vInfo) without whose visibility is
  36.             
  37.             repeat with rf in rootFiles
  38.                 if (rf is not in kasDontDo) then ¬
  39.                     set fsObjs to fsObjs & {(((vol alias of vInfo) as string) & rf) as alias}
  40.             end repeat
  41.         end if
  42.     end repeat
  43.     
  44.     -- Do items
  45.     repeat with fsObj in fsObjs
  46.         DoOne(fsObj)
  47.     end repeat
  48.     
  49.     display info gasInfoWind message "DONE!"
  50.     
  51.     pause for 5 with seconds timing -- Let screen wait...
  52.     
  53.     set gasInfoPos to screen location of ¬
  54.         (display info gasInfoWind with disposal)
  55.     
  56.     pfSave() -- Save window location
  57.     
  58.     set choice to ¬
  59.         display dialog ("Quit Finder to cause rebuild now?" & return & return & ¬
  60.             "Answering No will cause the Desktop to be rebuilt when the computer is next started") ¬
  61.             buttons {"No", "Yes"} default button 1
  62.     if (button returned of choice is "Yes") then
  63.         tell application "Finder" to quit
  64.         pause for 5 with seconds timing
  65.         ignoring application responses
  66.             tell application "Finder" to run
  67.         end ignoring
  68.     end if
  69. end run
  70.  
  71.  
  72. on DoOne(fsObj)
  73.     set aFileInfo to (alias info from fsObj)
  74.     
  75.     display info gasInfoWind ¬
  76.         message "File: " & (original name of aFileInfo) ¬
  77.         at line 2
  78.     
  79.     set gasChecked to gasChecked + 1
  80.     
  81.     try
  82.         set myInfo to (extended info for fsObj)
  83.     on error
  84.         TrashFile(fsObj, "Info error.")
  85.         return
  86.     end try
  87.     
  88.     set invisible status of myInfo to false
  89.     
  90.     try
  91.         set the catalog info of fsObj to myInfo
  92.     on error
  93.         beep
  94.     end try
  95.     
  96.     TrashFile(fsObj, "Invisible")
  97.     
  98.     display info gasInfoWind ¬
  99.         message ("Checked: " & gasChecked) ¬
  100.         at line 7 ¬
  101.         using color 15
  102. end DoOne
  103.  
  104.  
  105. on TrashFile(fsObj, reason)
  106.     display info gasInfoWind ¬
  107.         message reason at line 3
  108.     
  109.     try
  110.         collate fsObj with the trasher
  111.     on error err
  112.         display info gasInfoWind ¬
  113.             message ("Error: " & err) ¬
  114.             at line 12 ¬
  115.             using color (15 * 1024)
  116.         beep
  117.     end try
  118.     
  119.     set gasTrashed to gasTrashed + 1
  120.     
  121.     display info gasInfoWind ¬
  122.         message ("Trashed: " & gasTrashed) ¬
  123.         at line 8 ¬
  124.         using color (15 * 1024)
  125. end TrashFile
  126.  
  127.  
  128. on pfLoad()
  129.     try
  130.         set ourPrefs to (load preference named kasPrefName)
  131.         set gasInfoPos to item 1 of ourPrefs
  132.     on error
  133.         set gasInfoPos to {-1, -1}
  134.     end try
  135. end pfLoad
  136.  
  137.  
  138. on pfSave()
  139.     save preference {gasInfoPos} named kasPrefName
  140. end pfSave
  141.